/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.c.a.a;

import com.qihoo.c.a.a.a.b;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.message.BasicHeader;

public class g implements HttpEntity {
    private static final char[] a = "-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
    private final c b;
    private final Header c;
    private long d;
    private volatile boolean e;

    public g(d paramd, String paramString, Charset paramCharset) {
        if (paramString == null)
            paramString = a();
        if (paramd == null)
            paramd = d.a;
        this.b = new c("form-data", paramCharset, paramString, paramd);
        this.c = new BasicHeader("Content-Type", a(paramString, paramCharset));
        this.e = true;
    }

    public g() {
        this(d.a, null, null);
    }

    protected String a(String paramString, Charset paramCharset) {
        StringBuilder localStringBuilder = new StringBuilder();
        localStringBuilder.append("multipart/form-data; boundary=");
        localStringBuilder.append(paramString);
        if (paramCharset != null) {
            localStringBuilder.append("; charset=");
            localStringBuilder.append(paramCharset.name());
        }
        return localStringBuilder.toString();
    }

    protected String a() {
        StringBuilder localStringBuilder = new StringBuilder();
        Random localRandom = new Random();
        int i = localRandom.nextInt(11) + 30;
        for (int j = 0; j < i; ++j)
            localStringBuilder.append(a[localRandom.nextInt(a.length)]);
        return localStringBuilder.toString();
    }

    public void a(a parama) {
        this.b.a(parama);
        this.e = true;
    }

    public void a(String paramString, b paramb) {
        a(new a(paramString, paramb));
    }

    public boolean isRepeatable() {
        Iterator localIterator = this.b.a().iterator();
        while (localIterator.hasNext()) {
            a locala = (a) localIterator.next();
            b localb = locala.b();
            if (localb.e() < 0L)
                return false;
        }
        return true;
    }

    public boolean isChunked() {
        return (!(isRepeatable()));
    }

    public boolean isStreaming() {
        return (!(isRepeatable()));
    }

    public long getContentLength() {
        if (this.e) {
            this.d = this.b.c();
            this.e = false;
        }
        return this.d;
    }

    public Header getContentType() {
        return this.c;
    }

    public Header getContentEncoding() {
        return null;
    }

    public void consumeContent() {
        if (!(isStreaming()))
            return;
        throw new UnsupportedOperationException("Streaming entity does not implement #consumeContent()");
    }

    public InputStream getContent() {
        throw new UnsupportedOperationException("Multipart form entity does not implement #getContent()");
    }

    public void writeTo(OutputStream paramOutputStream) {
        this.b.a(paramOutputStream);
    }
}